package com.shengyuan.manage_os.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.telephony.TelephonyManager;

import static com.shengyuan.manage_os.im.ECApplication.CheckDirectory;

/**
 * Created by Administrator on 2017/1/20.
 */

public class DeviceUtils extends Activity{
//    private static Context context = super.getApplication();
    //android获取手机型号
    public static String MODEL = Build.MODEL;
    //获取手机厂商
    public static String MANUFACTURER = Build.MANUFACTURER;
    //android获取手机品牌
    public static String BRAND = Build.BRAND;
    //android获取sdk版本号
    public static int SDK_INT = Build.VERSION.SDK_INT;
    //android获取系统版本号
    public static String RELEASE = Build.VERSION.RELEASE;
    //android中获取imei号
//    public static String IMEI = ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();

    private DeviceUtils(){}
    private static DeviceUtils deviceUtils;
    public static DeviceUtils getinstrant(){
        if(deviceUtils == null){
            deviceUtils = new DeviceUtils();
        }
        return deviceUtils;
    }


    public boolean checkPermission(String Permission){

        boolean isHasPermission = ContextCompat.checkSelfPermission(this, Permission)
                != PackageManager.PERMISSION_GRANTED;
        return isHasPermission;
    }

    public void requestPermission(String[] Permission,int permsRequestCode){

        ActivityCompat.requestPermissions(this,Permission, permsRequestCode);
    }

    @Override
    public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults){

        PackageManager pm = getPackageManager();
        boolean permission = (PackageManager.PERMISSION_GRANTED ==
                pm.checkPermission(permissions[0], "com.shengyuan.manage_os"));
        if (permission) {
            switch (permsRequestCode){
                case 100:
                    CheckDirectory();
                    System.out.println("&&&&&&*****"+permissions[0]+"====授权成功");
                    break;
                case 200:
                    System.out.println("&&&&&&*****"+permissions[0]+"====授权成功");
                    break;
                case 300:

                    System.out.println("&&&&&&*****"+permissions[0]+"====授权成功");
                    break;


            }
//            CheckDirectory();
//            System.out.println("&&&&&&*****====授权成功");
        }else {
            //用户授权拒绝之后，友情提示一下就可以了
            System.out.println("&&&&&&*****====授权失败");
        }

    }


}
